package main

import (
	"fmt"
	"log"
	"net/rpc"
	"os"
)

type Args struct {
	A, B int
}
type Quotient struct {
	Quo, Rem int
}

func main() {

	if len(os.Args) != 2 {
		fmt.Println("Usage:", os.Args[0], " server")
		os.Exit(1)
	}
	serverAddress := os.Args[1]
	client, err := rpc.DialHTTP("tcp", serverAddress+":1234")
	if err != nil {
		log.Fatal("dialing:", err)
	}
	// 远程调用
	args := Args{17, 8}
	var reply int
	err = client.Call("Arith.Multiply", args, &reply)
	if err != nil {
		fmt.Println("call arith failed error:", err)
	}
	fmt.Printf("arith:%d*%d = %d ", args.A, args.B, reply)
	var quo Quotient
	err = client.Call("Arith.Divide", args, &quo)
	fmt.Printf("res Quo = %d, Rem = %d", quo.Quo, quo.Rem)
}
